<%= form_for(@control_group) do |f| %>
  <% if @control_group.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@control_group.errors.count, "error") %> prohibited this control_group from being saved:</h2>

      <ul>
      <% @control_group.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>


  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :max %><br />
    <%= f.number_field :max %>
  </div>
  <div class="field">
    <%= f.label :min %><br />
    <%= f.number_field :min %>
  </div>

  <div class="field">
    <%= f.label :candidates %><br />
    <% @candiates.each do |c| %>    
  <%= check_box_tag "control_group[candidate_ids][]", c.id, @control_group.candidates.map(&:id).include?(c.id) %> <%= c.name %>
<% end %>
<%= hidden_field_tag 'control_group[candidate_ids][]','' %>
  </div>


  <div class="field">
    <%= f.label :orgs %><br />
    <% @orgs.each do |org| %>    
  <%= check_box_tag "control_group[org_ids][]", org.id, @control_group.orgs.map(&:id).include?(org.id) %> <%= org.fullname %>
<% end %>
<%= hidden_field_tag 'control_group[org_ids][]','' %>
  </div>

  <div class="field">
    <%= f.label :questions %><br />
    <% @questions.each do |q| %>    
  <%= check_box_tag "control_group[question_ids][]", q.id, @control_group.questions.map(&:id).include?(q.id) %> <%= q.text %>
<% end %>
<%= hidden_field_tag 'control_group[question_ids][]','' %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
